# Maintainer: Diego Sogari <diego.sogari@falker.com.br>

_realname=gflags
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.2.74bcd20
pkgrel=1
pkgdesc="Google's Commandline flags module for C++ (mingw-w64)"
arch=('any')
url="https://gflags.github.io/gflags/"
license=('New BSD License')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
checkdepends=("${MINGW_PACKAGE_PREFIX}-gtest")
commit=74bcd20c0e5b904a67e37abf0c1262824ff9030c
source=("${_realname}-${commit}.zip::https://codeload.github.com/gflags/gflags/zip/${commit}"
        "${_realname}-${pkgver}.patch")
sha256sums=('d139f50a6f8c1ade9d7ab8bb8c0fde484d9feb410dacb5079a036adbc701405a'
            '97e824dc7c2511ecf07b91b0935029eda1885148dff5218b08a4b0dbb3e244a6')

prepare() {
  cd "${srcdir}/${_realname}-${commit}"
  patch -Np1 -i "../${_realname}-${pkgver}.patch"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_STATIC_LIBS=YES \
    -DBUILD_SHARED_LIBS=YES \
    -DBUILD_TESTING=YES \
    "../${_realname}-${commit}"

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
